public class AddExpression extends EqualExpression {

	DataInfo dataInfo;
	
	private MultExpression multExpr;
	private int op;
	private AddExpression addExpr;

	public static final int PO = 1;
	public static final int MO = 2;

	public AddExpression() {

	}

	public AddExpression(MultExpression t, int o, AddExpression e, DataInfo dataInfo) {
		multExpr = t;
		op = o;
		addExpr = e;
		
		this.dataInfo = dataInfo;
	}

	public String toString() {
		String ret = "AdditiveExpression\n";

		String s = "";
		s += "| " + multExpr.toString();

		if (addExpr != null) {

			if (op == PO)
				s += "| " + "+\n";
			else
				s += "| " + "-\n";

			s += "| " + addExpr.toString();
		}

		for (String st : s.split("\n"))
			ret += "| " + st + "\n";

		return ret;
	}

	public String getType() throws SemanticException {

		// if(addExpr != null)
		// return("int");
		return (multExpr.getType());

	}

	public void check() throws SemanticException {

		if (addExpr != null) {

			if (!addExpr.getType().equalsIgnoreCase(multExpr.getType())
					|| (!addExpr.getType().equalsIgnoreCase("int") && !addExpr
							.getType().equalsIgnoreCase("float")))
			{
				String details = "The children of the arithmetic expression do not have the same type or are not numbers.";
				if(dataInfo != null)
					throw new SemanticException(dataInfo.lineNumber,dataInfo.charNumber,dataInfo.line,details);
				else
					throw new SemanticException(details);
			}
			multExpr.check();
			addExpr.check();

		} else {

			multExpr.check();

		}

	}

}
